'use strict';
const BaseController = require('./base');
const serviceName = 'idleCategory';

class IdleCategoryController extends BaseController {
  constructor(ctx) {
    super(ctx, serviceName);
  }

  async tree() {
    const { ctx } = this;
    const result = await ctx.service[this.serviceName].getTree(ctx.query);
    ctx.success(result);
  }

  async getByType() {
    const { ctx } = this;
    const { type } = ctx.query;
    if (!type) {
      ctx.throw(400, '类型参数不能为空');
    }
    const result = await ctx.service[this.serviceName].getByType(type);
    ctx.success(result);
  }

  async getSubTypes() {
    const { ctx } = this;
    const { type } = ctx.query;
    if (!type) {
      ctx.throw(400, '类型参数不能为空');
    }
    const result = await ctx.service[this.serviceName].getSubTypes(type);
    ctx.success(result);
  }
}

module.exports = IdleCategoryController;
